﻿@{
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
    List<WeChatParking.Entity.Enterprise> list = ViewBag.EnterpriseList;
}
<div class="">
    <div class="ibox-content">
        <div class="jqGrid_wrapper">
            <div class="col-sm-12 jqGrid-toolbar">
                <form class="form-inline search-form" id="search-form">
                    <label for="search_card_no">停车场</label>
                    <select class="form-control  sm" name="CCEnterpriseID" style="width: 120px;">
                        @foreach (var item in list)
                        {
                            <option value="@item.ID">@item.Enterprise_Name</option>
                        }
                    </select>
                    <div class="form-group">
                        <label for="search_paytime_begin">支付时间</label>
                    </div>
                    <div class="form-group">
                        <div>
                            <input type="text" class="form-control laydate-icon layer-date" id="search_paytime_begin" name="paytime_begin" value="@DateTime.Today.AddDays(-6).ToString("yyyy-MM-dd")">
                            <input type="text" class="form-control laydate-icon layer-date" id="search_paytime_end" name="paytime_end" value=" @DateTime.Today.ToString("yyyy-MM-dd")">
                        </div>

                    </div>
                    <button type="submit" class="btn btn-primary">
                        <i class="glyphicon glyphicon-search"></i>查询
                    </button>
                </form>

                <div class="btn-group " role="group">
                    <button class="btn btn-primary" id="btn-export">
                        <i class="glyphicon glyphicon-download-alt"></i>导出
                    </button>
                </div>
            </div>
            <table id="grid"></table>
            <div id="grid_pager"></div>
        </div>
    </div>
</div>

@section BodyFooter{
    <script>
        $(document).ready(function () {

            $("#grid").jqGrid({
                url: '/Report/OrderDataReport',
                multiselect: false,
                colNames: ["订单号", "姓名", "车牌号", "物业名称", "停车场名称", "支付金额", "云闪付", "微信支付", "支付宝", "通联支付", "现金支付", "支付时间", "订单创建时间"],
                colModel: [{
                    name: "order_id",
                    index: "order_id",
                    key: true,
                },
                {
                    name: "Wxuser_name",
                    index: "Wxuser_name",
                    width: 80
                },
                {
                    name: "car_no",
                    index: "car_no",
                    width: 80
                },
                 {
                     name: "Enterprise_Name",
                     index: "Enterprise_Name",
                     width: 80
                 },
                  {
                      name: "CCEnterprise_Name",
                      index: "CCEnterprise_Name",
                      width: 80
                  },
                {
                    name: "pay_fee",
                    index: "pay_fee",
                    align: 'right',
                    width: 70,
                    formatter: "currency"
                },
                {
                    name: "UnionPay_fee",
                    index: "UnionPay_fee",
                    align: 'right',
                    width: 70,
                    formatter: "currency"
                }
                ,
                {
                    name: "Weixin_fee",
                    index: "Weixin_fee",
                    align: 'right',
                    width: 70,
                    formatter: "currency"
                }
                ,
                {
                    name: "Alipay_fee",
                    index: "Alipay_fee",
                    align: 'right',
                    width: 70,
                    formatter: "currency"
                }
                ,
                {
                    name: "Tonglian_fee",
                    index: "Tonglian_fee",
                    align: 'right',
                    width: 70,
                    formatter: "currency"
                }
                ,
                {
                    name: "XJPay_fee",
                    index: "XJPay_fee",
                    align: 'right',
                    width: 70,
                    formatter: "currency"
                }
               ,
                {
                    name: "pay_time",
                    index: "pay_time",
                    width: 120,
                    formatter: 'date',
                    formatoptions: { newformat: 'Y-m-d H:i:s' }
                },
                {
                    name: "create_time",
                    index: "create_time",
                    width: 120,
                    formatter: 'date',
                    formatoptions: { newformat: 'Y-m-d H:i:s' }
                }],
                caption: "支付报表",
                footerrow: true,
                userDataOnFooter: true
            });

            $("#grid").adaptGridSizeInWindow();
        });



        $('#search-form').submit(function () {
            var data = $(this).serializeArray();
            var postData = {};
            $.each(data, function (i, n) {
                postData[n.name] = n.value;
            });

            $("#grid").jqGrid('setGridParam', {
                postData: postData, //发送数据
                page: 1
            }).trigger("reloadGrid"); //重新载入
            $('#btn-export').data('export-query', postData);

            return false;
        });

        $('#btn-export').click(function () {

            var postData = $('#btn-export').data('export-query');
            if (!postData) {
                toastr.error('请先执行查询');
                return;
            }

            $.postJsonAjax('/Report/DownloadOrderData', postData, function (rsp) {
                if (rsp.Code == 1) {
                    var el = $('<a id="download-file" style="display:none"></a>').appendTo(document.body);
                    el[0].href = rsp.Message;
                    el[0].click();
                    el.remove();
                } else {
                    toastr.error(rsp.Message);
                }
            });
        });

    </script>

    <script>
        var start = {
            elem: '#search_paytime_begin',
            format: 'YYYY-MM-DD',
            max: laydate.now(), //最大日期
            istime: false,
            istoday: true,
            choose: function (datas) {
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };
        var end = {
            elem: '#search_paytime_end',
            format: 'YYYY-MM-DD',
            max: laydate.now(),
            istime: false,
            istoday: true,
            choose: function (datas) {
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };
        laydate(start);
        laydate(end);
    </script>

}
